import * as Mock from "mockjs";
import config from "/@/config";

declare type Option = {
  url: string;
  type: string;
  body: string;
};

declare type MockResponse = {
  code: string;
  status: string;
  msg?:string;
  data?: any | any[];
};

const { baseURL } = config;
Mock.mock(`${baseURL}/auth/login`, "post", (option: Option):MockResponse => {
  console.log("option", option);
  const { username, password } = JSON.parse(option.body);
  if (username === "admin" && password === "123") {
    return {
      code: "200",
      status: "ok",
      data: {
        username,
        name: "gly",
        token: "token:admin",
      },
    };
  }

  return {
    code: "500",
    status: "failed",
    msg: "账号密码错误",
  };
});
